$(function () {
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
    //----------------------------------------------------------------
    //  页面查询参数
    var query = {
        pagenum: 1, //页码值
        pagesize: 10, //每页显示几条数据
        lab_class_name: '', //宿舍名称
        lab_class_appointment_person: '', //宿舍负责人
    }
    // 渲染分页功能
    function renderPage(total) {
        // console.log(total);
        laypage.render({
            elem: 'pageBox', //分页容器的id
            count: total, //数据总数，从服务端得到
            limit: query.pagesize, //每页显示几条数据
            curr: query.pagenum,
            layout: ["count", "limit", "prev", "page", "next", "skip"],
            limits: [10, 15, 20, 25],
            jump: function (obj, first) {
                // console.log(first);
                query.pagenum = obj.curr;
                query.pagesize = obj.limit;
                // 首行不执行
                if (!first) {
                    init_Lab_Log_List()
                }
            },

        });
    }
    //----------------------------------------------------------------
    // 调用获取宿舍预约记录的函数
    init_Lab_Log_List();
    //----------------------------------------------------------------
    // 获取全部宿舍预约记录的函数
    function init_Lab_Log_List() {
        var lab_class_name = $('#form_search [name = lab_class_name ]').val();
        var lab_class_appointment_person = $('#form_search [name = lab_class_appointment_person]').val();
        query.lab_class_name = lab_class_name;
        query.lab_class_appointment_person = lab_class_appointment_person;
        $.ajax({
            method: 'GET',
            url: '/my/labManage/lab_log_List/',
            data: query,
            success: function (res) {
                // console.log(res);
                var htmStr = template('tpl_lab_log_list', res);
                $('tbody').html(htmStr)
                renderPage(res.total)
            }
        })
    }
    //----------------------------------------------------------------
    //模糊搜索需要的信息
    $('#form_search').on('submit', function (e) {
        e.preventDefault()
        init_Lab_Log_List();
    })
})